$(document).ready(function() {
    $("body").tooltip({ selector: '[data-toggle=tooltip]' });

    // scroll header
    var navpos = $('#layout-wrap').offset();
    console.log(navpos.top);
    $(window).bind('scroll', function() {
      if ($(window).scrollTop() > navpos.top) {
        $('#header-wrap').addClass('navbar-fixed-top');
        $('#keatas').addClass('visible');
       }
       else {
         $('#header-wrap').removeClass('navbar-fixed-top');
         $('#keatas').removeClass('visible');
       }
    });

    // icon social
    $('.social_active').hoverdir( {} );

    // efek animasi waypoint
    var animatedDivs = new Array()
    var i = 0
    $('.nop-animasi').each(function() {
        animatedDivs[i] = $(this);
        i++;
    });

    for (i = 0; i < animatedDivs.length; i++) {
        var div = animatedDivs[i];
        div.waypoint({
            handler: function(direction) {
                if (direction == 'down') {// up, down, left, or right
                    applyEffect($(this));
                }
            },
            offset: 'bottom-in-view'
        });
    }


    function applyEffect(div) {
        var effect = div.data('animation');
        div.removeClass("transparent").addClass("opaque").addClass(effect);

    }

    // smooth scroll to top

    $(function() {
    $('a[href*=#]:not([href=#])').click(function() {
      if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
        var target = $(this.hash);
        target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
        if (target.length) {
          $('html,body').animate({
            scrollTop: target.offset().top
          }, 1000);
          return false;
        }
      }
    });
  });

});

